//
//  LSMatchExponentDataVController.m
//  LookScore
//
//  Created by wr on 2018/1/26.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSMatchExponentDataVController.h"
#import "LSCustomHeaderView.h"
#import "LSMatchExponentDataCell.h"
#import "LSExponentModel.h"
@interface LSMatchExponentDataVController ()<UITableViewDelegate,UITableViewDataSource>

@property(strong,nonatomic)UITableView *leftTableView;

@property(strong,nonatomic)UITableView *rightTableView;

@property(strong,nonatomic)NSMutableArray *modelArray;

@property(assign,nonatomic)NSInteger  chooseIndex;

/**类型*/
@property (nonatomic, copy) NSString *dataType;


@property (nonatomic, assign) NSInteger btnSelectedTag;

@end

@implementation LSMatchExponentDataVController


-(UITableView *)leftTableView{
    if (!_leftTableView) {
        _leftTableView = [[UITableView alloc]init];
        _leftTableView.delegate = self;
        _leftTableView.dataSource = self;
        _leftTableView.backgroundColor =LSBackGroundColor;
        _leftTableView.showsVerticalScrollIndicator = NO;
        _leftTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _leftTableView;
}

-(UITableView *)rightTableView{
    if (!_rightTableView) {
        _rightTableView = [[UITableView alloc]init];
        _rightTableView.delegate = self;
        _rightTableView.dataSource = self;
        _rightTableView.backgroundColor =LSBackGroundColor;
        _rightTableView.showsVerticalScrollIndicator = NO;
        _rightTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _rightTableView;
}

-(NSMutableArray *)modelArray{
    if(!_modelArray){
        _modelArray=[[NSMutableArray alloc]init];
    }
    return _modelArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.dataType = @"yp";
    
    [self initPagerView];
}


#pragma mark 🔥 tableViewDelegate tableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if ([self.dataType isEqualToString:@"op"]) {
        
        if (tableView == self.leftTableView) {
            return self.model.OddsChangeRecordList.count;
        }else{
            if (self.model.OddsChangeRecordList.count == 0) {
                return 0;
            }
            OddsChangeRecordList * item = self.model.OddsChangeRecordList[_chooseIndex];
            return item.companyData.count;
        }
    }else if ([self.dataType isEqualToString:@"yp"]){
        
        if (tableView == self.leftTableView) {
            return self.model.AIHistoricaDataList.count;
        }else{
            if (self.model.AIHistoricaDataList.count == 0) {
                return 0;
            }
            AIHistoricaDataList * item = self.model.AIHistoricaDataList[_chooseIndex];
            return item.companyData.count;
        }
        
    }else{
        
        
        if (tableView == self.leftTableView) {
            return self.model.SDHistoricaDataList.count;
        }else{
            //
            if (self.model.SDHistoricaDataList.count == 0) {
                return 0;
            }
            SDHistoricaDataList * item = self.model.SDHistoricaDataList[_chooseIndex];
            return item.companyData.count;
        }
    }

}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==0) {
        return 32;
    }
    return 30;//  tableView.rowHeight;
}


- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView==self.leftTableView) {
        LSMatchExponentCompanyDataCell *cell=[LSMatchExponentCompanyDataCell MatchExponentCompanyDataCellByTableView:tableView];
       
        if (indexPath.row==0) {
            cell.lineView.hidden=YES;
        }
        if ([self.dataType isEqualToString:@"op"]) {
            cell.model = self.model.OddsChangeRecordList[indexPath.row];
        }else if ([self.dataType isEqualToString:@"yp"]){
            cell.aiModel = self.model.AIHistoricaDataList[indexPath.row];
            
        }else{
            
            cell.sdModel = self.model.SDHistoricaDataList[indexPath.row];
        }
       
        return cell;
    }else{
        LSMatchExponentDataCell *cell=[LSMatchExponentDataCell MatchExponentDataCellByTableView:tableView];
//        [cell fasleData:indexPath.row];
        
        cell.dataType = self.dataType;
        if ([self.dataType isEqualToString:@"op"]) {
            OddsChangeRecordList * item = self.model.OddsChangeRecordList[_chooseIndex];
            cell.model = item.companyData[indexPath.row];
        }else if ([self.dataType isEqualToString:@"yp"]){
            AIHistoricaDataList *item = self.model.AIHistoricaDataList[_chooseIndex];
            
            cell.model = item.companyData[indexPath.row];
        }else{
            
            SDHistoricaDataList * item = self.model.SDHistoricaDataList[_chooseIndex];
            cell.model = item.companyData[indexPath.row];
        }
        
        
        if (indexPath.row==0) {
            cell.lineView.hidden=YES;
        }
        return cell;
    }

}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (tableView == self.leftTableView) {
        UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.leftTableView.frame.size.width, 30)];
        headerView.backgroundColor = Color(247, 247, 247);
        UILabel * label = [[UILabel alloc] initWithFrame:headerView.frame];
        label.text = @"公司";
        label.font = LSFontSize12;
        label.textColor = LSSubColorB4B4B4;
        label.textAlignment = NSTextAlignmentCenter;
        
        [headerView addSubview:label];
        
        return headerView;
    }else{
        UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.rightTableView.frame.size.width, 30)];
        headerView.backgroundColor = Color(247, 247, 247);
        NSArray * titleArray;
        if ([self.dataType isEqualToString:@"yp"]) {
            titleArray = @[@"时间",@"主胜",@"让球",@"客胜"];
        }else if ([self.dataType isEqualToString:@"op"]){
            
            titleArray = @[@"时间",@"胜",@"平",@"负"];
        }else{
             titleArray = @[@"时间",@"大球",@"盘口",@"小球"];
        }
        
//         NSArray *;
        for (NSInteger i = 0; i<titleArray.count; i++) {
            UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(headerView.frame.size.width/4 * i, 0, headerView.frame.size.width/4 , 30)];
            label.text = titleArray[i];
            label.font = LSFontSize12;
            label.textColor = LSSubColorB4B4B4;
            label.textAlignment = NSTextAlignmentCenter;
            
            [headerView addSubview:label];
        }
        return headerView;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView == self.leftTableView) {
        self.chooseIndex = indexPath.row;
        [self.rightTableView reloadData];
    }
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 30;
}

#pragma mark 🔥 UI
-(void)initPagerView{

    UIView *aboveView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, LSScreenWidth, 35)];
    aboveView.backgroundColor=LSNavMainColor;
    [self.view addSubview:aboveView];
    
    LSTopSegmentSortView *segmentView=[[LSTopSegmentSortView alloc]initWithFrame:CGRectMake(60, 0, LSScreenWidth-120, 35)];
    segmentView.unSelectedColor=LSTitleWhiteColor;
    segmentView.selectedColor=LSNavTitlenColor;
    
    if ([self.dataType isEqualToString:@"yp"]) {
        self.btnSelectedTag = 1;
    }else if ([self.dataType isEqualToString:@"op"]){
        self.btnSelectedTag = 0;
    
    }else{
        self.btnSelectedTag = 2;
    }
    [segmentView addBottomArray:@[@"欧赔",@"亚盘",@"大小球"] selectButton:self.btnSelectedTag];
    [aboveView addSubview:segmentView];
    segmentView.butonActionBlock = ^(NSInteger tag) {
        if (tag == 0) {
            self.dataType = @"op";
        }else if (tag == 1){
            
            self.dataType = @"yp";
        }else{
            
            self.dataType = @"dxq";
        }
        
        [self.leftTableView reloadData];
        [self.rightTableView reloadData];
    };
    
    self.leftTableView.frame=CGRectMake(0, CGRectGetMaxY(aboveView.frame), LSScreenWidth/5, LSScreenHeight-CGRectGetMaxY(aboveView.frame));
    self.leftTableView.backgroundColor=LSSubGrayColorf7;
    [self.view addSubview:self.leftTableView];
    
    self.rightTableView.frame=CGRectMake(CGRectGetMaxX(self.leftTableView.frame), CGRectGetMaxY(aboveView.frame), (LSScreenWidth/5)*4, LSScreenHeight-CGRectGetMaxY(aboveView.frame));
    self.rightTableView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:self.rightTableView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
